package edu.nf.relaxenjoy.common.configure;

import edu.nf.relaxenjoy.common.util.RedisUtils;
import edu.nf.relaxenjoy.web.interceptor.UserLoginInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author zhu
 * @date 2024-12-10
 */
@Configuration
@RequiredArgsConstructor
public class MvcConfigure extends WebMvcConfigurationSupport {

    private final RedisUtils redisUtils;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new UserLoginInterceptor(redisUtils))
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/auth/**","/api/util/**","/api/search/**");
        super.addInterceptors(registry);
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowedHeaders("*")
                .exposedHeaders("*")
                .maxAge(3600);
    }
}
